/**
 * 获取GET请求中的键值表
 * @param {Object} url URL
 */
function get_url_kv(url) {
	var url_array = url.split('?');
	var param_array = url_array[1].split('&');
	var kv = [];
	for (var index in param_array) {
		var _param = param_array[index];
		var _kv_array = _param.split('=');
		kv[_kv_array[0]] = _kv_array[1];
	}
	return kv;
}

/**
 * 从键值表中获取指定的键值
 * @param {Object} _kv 键值表
 * @param {Object} name 要获取的键
 */
function search_url_kv(_kv, name) {
	var value = null;
	for (var index in _kv) {
		if (index === name) {
			value = _kv[index];
			break;
		}
	}
	return value;
}

/**
 * 跳转页面到当前位置
 * @param {Object} local 当前位置
 */
function goto_local(local) {
	if (local === '' || local === 'bedroom') {
		location.href = 'bedroom.html';
	} else if (local === 'livingroom') {
		location.href = 'livingroom.html';
	} else if (local === 'computer_room') {
		location.href = 'computer_room.html';
	}
}

/**
 * 显示剧情
 * @param {Object} index 剧情索引
 */
function show_plot(index, subplot_index) {
	if (typeof plots[index] !== 'undefined') {
		if (typeof plots[index][subplot_index] === 'undefined') {
			return '';
		} else {
			return plots[index][subplot_index];
		}
	}
	return '';
}

function e2c(voice, dom, innerHTML) {
	var dict = {
		'Map': '地图',
		'livingroom': '客厅',
		'computer room': '电脑房',
		'bedroom': '卧室',
		'Sleep': '睡觉',
		'Turn on': '开机',
	};
	if (fs.existsSync('audio/' + dict[innerHTML] + '.mp3')) {
		voice.src = 'audio/' + dict[innerHTML] + '.mp3';
		voice.play();
	}
	dom.innerHTML = dict[innerHTML];
}

function c2e(dom, innerHTML) {
	var dict = {
		'地图': 'Map',
		'客厅': 'livingroom',
		'电脑房': 'computer room',
		'卧室': 'bedroom',
		'睡觉': 'Sleep',
		'开机': 'Turn on',
	};
	dom.innerHTML = dict[innerHTML];
}

function show_map() {
	layer.open({
		closeBtn: 0,
		btn: 'Close',
		title: '地图',
		content: $('#map').html()
	});
}
